//
//  CZMainTabBar.swift
//  swift版新浪微博
//
//  Created by mac on 15/12/15.
//  Copyright © 2015年 mac. All rights reserved.
//

import UIKit

class CZMainTabBar: UITabBar {

    private let count = 5
    override func layoutSubviews() {
        
        let width = self.bounds.width / CGFloat(count)
        
        let frame = CGRect(x: 0, y:0, width: width, height: self.bounds.height)
        
        var index = 0
        
        for view in self.subviews
        {
        
            if view is UIControl && !(view is UIButton)
            {
                view.frame = CGRectOffset(frame,CGFloat(index) * width, 0)
                
                index++
                if index==2{
                    index++
                }
            }
            
           
        }
        componseButton.frame = CGRectOffset(frame, 2*width, 0)
    }
    lazy var componseButton:UIButton =
    {
        let button = UIButton()
        button.setBackgroundImage(UIImage(named: "tabbar_compose_button"), forState: UIControlState.Normal)
        button.setBackgroundImage(UIImage(named: "tabbar_compose_button_highlighted"), forState: UIControlState.Highlighted)
        
        // 设置按钮图片
        button.setImage(UIImage(named: "tabbar_compose_icon_add"), forState: UIControlState.Normal)
        button.setImage(UIImage(named: "tabbar_compose_icon_add_highlighted"), forState: UIControlState.Highlighted)
        
        self.addSubview(button)
        return button
        
    }()
}
